home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / lang / ace102.lha / include / inputs.h < prev    next >
Text File  |  1993-01-30  |  2KB  |  151 lines

  1.  
  2. { ** Get INPUT from the current SCREEN **
  3.  
  4.   INPUTS$ - input a string.
  5.   INPUTS% - input a short integer.
  6.   INPUTS& - input a long integer.
  7.   INPUTS! - input a single-precision value.
  8.   
  9.   Author: David J Benn
  10.     Date: 8th,14th July 1992,
  11.       1st January 1993
  12. }
  13.  
  14. SUB cursor
  15.   oldfg%=window(10)
  16.   color window(6),0
  17.   prints "|";
  18.   locate csrlin,pos-1
  19.   color oldfg%,0
  20. END SUB
  21.  
  22. SUB inputs$
  23. shortint ccol
  24. const MAXCOL=80
  25.  
  26.  '..start column
  27.  ccol=pos
  28.  
  29.  cursor
  30.  
  31.  '..input a string.
  32.  z$=""
  33.  repeat
  34.   '..await a keystroke
  35.   repeat
  36.     x$=inkey$
  37.   until x$<>""
  38.   '..if printable, print it.
  39.   if asc(x$) >= 32 and pos < MAXCOL then
  40.     z$=z$+x$
  41.     prints x$;
  42.     cursor
  43.   else
  44.     '..BS or DEL?
  45.     if asc(x$)=8 and pos > ccol then
  46.       '..erase cursor and character
  47.       locate csrlin,pos-1
  48.       prints "  ";
  49.       locate csrlin,pos-2
  50.       cursor
  51.       '..chop off right-most character
  52.       z$=left$(z$,len(z$)-1)
  53.     end if      
  54.   end if
  55.  until x$=chr$(13)
  56.  
  57.  '..erase cursor
  58.  prints " "
  59.  
  60.  '..return string
  61.  inputs$=z$
  62.  
  63. END SUB
  64.  
  65. SUB spacestripped$(x$)
  66. shortint l,i,s
  67.  
  68.  '..strip ALL whitespace from x$ 
  69.  '..(VAL does this too).
  70.  
  71.  y$=""
  72.  i=1
  73.  l=len(x$)
  74.  
  75.  while i<=l
  76.    s$=mid$(x$,i,1)
  77.    if s$ > " " then y$=y$+s$
  78.    ++i
  79.  wend
  80.  
  81.  spacestripped$ = y$
  82. END SUB
  83.  
  84. SUB inputs%
  85. shortint l,i,s,sign
  86.  
  87.  num$ = inputs$
  88.  num$ = spacestripped$(num$)
  89.  
  90.  '..leading + or - ?
  91.  first$=mid$(num$,1,1) 
  92.  if first$="-" or first$="+" then
  93.    case 
  94.      first$="-" : sign = -1
  95.      first$="+" : sign =  1
  96.    end case
  97.    num$=right$(num$,len(num$)-1)
  98.  else
  99.    sign=1
  100.  end if
  101.  
  102.  '..get value
  103.  i=1
  104.  l=len(num$)
  105.  num%=0
  106.  
  107.  repeat 
  108.    s=asc(mid$(num$,i,1))
  109.    num% = num%*10 + s-asc("0")    
  110.    ++i
  111.  until i>l or s<asc("0") or s>asc("9")
  112.  
  113.  inputs% = num%*sign
  114. END SUB
  115.  
  116. SUB inputs&
  117. shortint l,i,s,sign
  118.  
  119.  num$ = inputs$
  120.  num$ = spacestripped$(num$)
  121.  
  122.  '..leading + or - ?
  123.  first$=mid$(num$,1,1) 
  124.  if first$="-" or first$="+" then
  125.    case 
  126.      first$="-" : sign = -1
  127.      first$="+" : sign =  1
  128.    end case
  129.    num$=right$(num$,len(num$)-1)
  130.  else
  131.    sign=1
  132.  end if
  133.  
  134.  '..get value
  135.  i=1
  136.  l=len(num$)
  137.  num&=0
  138.  
  139.  repeat 
  140.    s=asc(mid$(num$,i,1))
  141.    num& = num&*10& + s-asc("0")    
  142.    ++i
  143.  until i>l or s<asc("0") or s>asc("9")
  144.  
  145.  inputs& = num&*sign
  146. END SUB
  147.   
  148. SUB inputs!
  149.  inputs!=val(inputs$)
  150. END SUB
  151.